package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Setmeal;
import com.sky.entity.SetmealDish;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishItemVO;
import com.sky.vo.SetmealVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface SetmealMapper {

    @Select("SELECT * FROM setmeal WHERE category_id = #{id}")
    List<Setmeal> getSetmealByCategoryId(Long id);
    List<Long> getSetMealIdsByDishIdUseBatch(List<Long> ids);


    @Select("SELECT * FROM setmeal WHERE category_id = #{categoryId} and status = #{status}")
    List<Setmeal> getSetmealsWithEableStatusByCategoryId(Setmeal setmeal);

    List<DishItemVO> getDishItemVOBySetmealId(Long setmealId);


    @AutoFill(value= OperationType.UPDATE)
    @Update("UPDATE setmeal SET status = #{status} ,update_time=#{updateTime},update_user=#{updateUser} WHERE id = #{id}")
    void updateSetmealStatus(Setmeal setmeal);


    @Select("select count(*) from setmeal_dish left join dish on setmeal_dish.dish_id = dish.id where setmeal_dish.id = #{id} and dish.status= 0")
    Integer findNotSaleDishCountsAssociatedSetmeal(Integer id);

    @AutoFill(value= OperationType.INSERT)
    void saveSetmeal(Setmeal setmeal);

    void saveSetmealDishItemsByBatches(List<SetmealDish> setmealDishes);

    @Select("SELECT * FROM setmeal WHERE id = #{id}")
    Setmeal getSetmealById(Integer id);


    @Select("select * from setmeal_dish where setmeal_id = #{id}")
    List<SetmealDish> getSetmealWithDishsById(Integer id);


    Integer findSetmealsStatusByBatch(@Param("ids") List<Integer> ids);

    void deleteSetmealByBatch(List<Integer> ids);

    void deleteSetmealDishByBatch(List<Integer> ids);

    @AutoFill(value= OperationType.UPDATE)
    void updateSetmeal(Setmeal setmeal);

    @Delete("delete from setmeal_dish where setmeal_id = #{id}")
    void deleteSetmealDishBySetmealId(Long id);

    Page<SetmealVO> getSetmealPage(SetmealPageQueryDTO setmealPageQueryDTO);
}
